<?php include("../components/autoload.php"); ?>
<?php include("../components/functions.php"); ?>
<?php include("../../components/connection.php"); ?>

<?php
	@header('Content-Type: text/html; charset=UTF-8'); 
	
	$team = new Tim($_GET['id']);
	
	if(file_exists('../../media/teams/logo/'.$team->grb)) {
		if (unlink ('../../media/teams/logo/'.$team->grb)) echo "Grb obrisan!<br />";
	}
	
	if(file_exists('../../media/teams/logo/'.$team->slika)) {
		if (unlink ('../../media/teams/logo/'.$team->grb)) echo "Slika obrisana!<br />";
	}
		
	$q = "DELETE FROM tim WHERE id = ". $team->id;
	if (mysql_query($q)) echo "Obrisan tim iz baze podataka!<br />";
		
	$q = "DELETE FROM ucestvuje WHERE tim = ". $team->id;
	if (mysql_query($q)) echo "Obrisan tim iz svih liga!<br />";
		
	$q = "DELETE FROM igra_za WHERE tim = ". $team->id;
	if (mysql_query($q)) echo "Obrisani igraci tima!<br />";
		
	$qq = "SELECT id FROM utakmica WHERE domacin = ". $team->id ." OR gost = ". $team->id;
	$rq = mysql_query($qq);
	if (mysql_num_rows($rq)) {
		while ($nq = mysql_fetch_array($rq)) {
			$q = "DELETE FROM statistika WHERE mec = ". $nq['id'];
			if (mysql_query($q)) echo "Obrisana statistika sa utakmice!<br />";
		}
	}
	unset ($qq, $rq, $nq);
	
	$q = "DELETE FROM utakmica WHERE domacin = ". $team->id ." OR gost = ". $team->id;
	if (mysql_query($q)) echo "Obrisane utakmice!<br />";
		
	unset($team);
	
?>